package com.forg.mvc.core.handle;

import java.lang.reflect.Method;

public abstract class AbstractHandler {
    
    public AbstractHandler(){
    }
    
    public AbstractHandler(Object o,Method m){
        this.instance = o;
        this.method = m;
    }
    
    Method method;
    
    Object instance;

    public Method getMethod() {
        return method;
    }

    public void setMethod(Method method) {
        this.method = method;
    }

    public Object getInstance() {
        return instance;
    }

    public void setInstance(Object instance) {
        this.instance = instance;
    }
    
    protected boolean beforeHandle(){
        
        return true;
    }
    
    public boolean handle(){
        
        if(!beforeHandle()){
            return false;
        }
        
        boolean ret = doHandle();
        
        ret = ret && afterHandle();
        
        return ret;
    }
    
    protected abstract boolean doHandle();
    
    protected boolean afterHandle(){
        
        return true;
    }

}
